/*
 * messaging.h
 *
 *  Created on: May 20, 2012
 *      Author: burek
 */

#ifndef MESSAGING_H_
#define MESSAGING_H_

#define MAX_PARAMS (128)

#define CM_NONE (0)
#define CM_INT (1)
#define CM_FLOAT (2)
#define CM_STRING (3)

#define CM_SEPARATOR (32)
#define CM_PARAM_SEPARATOR (';')

// Jedna poruka, primarno sredstvo komunikacije u protokolu,
// sastoji se od trocifrenog koda/tipa i liste parametara
// odvojenih sa ;
typedef struct
{
	int code;
	int paramCount;
	int pType[MAX_PARAMS];
	union
	{
		int ival;
		float fval;
		char * sval;
	} pVal[MAX_PARAMS];
	char * buffer;
	int length;
} CMessage;

CMessage * cm_createMessage(int code);
CMessage * cm_decodeMessage(const char * buffer, int length);
int cm_appendInt(CMessage * msg, int number);
int cm_appendFloat(CMessage * msg, float number);
int cm_appendString(CMessage * msg, const char * text);
int cm_finalizeMessage(CMessage * msg);
void cm_dumpParams(int id, CMessage * msg);
void cm_destroyMessage(CMessage * msg);

#endif /* MESSAGING_H_ */
